The Compiler

The KCL compiler translates a Lisp program stored in a source file into a C-language program, invokes the C-language compiler to compile the C-language program, and then generates an object file, called fasl file (or o-file because of the actual filetype). The compiled program in a fasl file is loaded by the function load.


Ordinarily, the object program generated by the KCL compiler scarcely does runtime error-checking for runtime efficiency. In addition, Lisp functions in the same source file are linked together and some system functions are open-coded in-line. To control runtime error checking, supply appropriate optimize declarations (see Section 7.1).


The KCL compiler processes the eval-when special form exactly as specified in the Common Lisp Reference Manual. However, all top-level forms in the source file are normally processed in compile-time-too mode, not in not-compile-time mode (see Section 5.3.3 of the Common Lisp Reference Manual). That is, each top-level form top-level-form is processed as if it were surrounded by the eval-when special form with the situations compile, load, and eval.



(eval-when (compile load eval) top-level-form)



There is no exception for this rule. Thus, for instance, in the example of set-macro-character form in Section 5.3.3 of the Common Lisp Reference Manual, the surrounding eval-when form is unnecessary in KCL. If it is desired that each top-level form be processed in not-compile-time mode, change the value of the KCL specific variable *eval-when-compile* as described below.


The KCL compiler is invoked by the functions compile-file, compile, and disassemble described below. In addition, the KCL compiler may be invoked directly by the Shell commands lc or lc1. These commands require the file name of the source file as their argument. Both lc and lc1 simply add ``.lsp'' to the file name argument to obtain the full name of the source file.



% lc filename



has the same effect as the compiler invocation (compile-file ``filename'') from within KCL, and



% lc1 filename



has the same effects as (compile-file ``filename'' :o-file t :c-file t :h-file t :data-file t).



compile-file input-pathname[Function]

&key :output-file :output-file :o-file :c-file :h-file :data-file

compile-file compiles the Lisp program stored in the file specified by input-pathname, and generates a fasl file. Also compile-file generates the following temporary files.



Temporary File  Contents
c-file  C version of the Lisp program
h-file  The include file referenced in the c-file
data-file  The Lisp data to be used at load time



If files of these names already exist, the old files will be deleted first. Usually, these intermediate files are automatically deleted after execution of compile-file.


The input-file is determined in the usual manner (see Section 2.9), except that, if the filetype is not specified, then the default filetype .lsp will be used. The keyword parameter :output-file defines the default directory and the default name to be applied to the output files (i.e., the fasl file and the temporary files). :output-file itself defaults to input-pathname. That is, if :output-file is not supplied, then the directory and the name of the input file will be used as the default directory and the default name for the output files. The filetypes of the output files are fixed as follows.



Output File  Filetype
fasl file  .o
c-file  .c
h-file  .h
data-file  .data



Each output file can be specified by the corresponding keyword parameter. If the value of the keyword parameter is nil, then the output file will be deleted after execution of compile-file. If the value of the keyword parameter is t, then the output file will be left in the default directory under the default name. Otherwise, the output file will be left in the directory under the name specified by the keyword parameter. The default value of :o-file is t , and the default values of :c-file, :h-file, and :data-file are all nil.



Example:

(compile-file 'foo)

The source file is ``FOO.lsp'' and the fasl file is ``FOO.o'' both in the current directory.

(compile-file 'foo.lish)

The source file is ``FOO.LISH'' and the fasl file is ``FOO.o''.

(compile-file ``/usr/mas/foo'' :output-file ``/usr/tai/baa'')

The source file is ``foo.lsp'' in the directory ``/usr/mas'', and the fasl file is ``baa.o'' in the directory ``/usr/tai''.



———— Note to KCL/AOS users ————



The compiler of KCL/AOS generates the following output files.



Output File  Filetype Contents
fasl file  .fasl The fasl file
c-file  .c C version of the Lisp program
h-file  .h The include file referenced in the c-file
ob-file  .ob The object file generated by the C compiler
data-file  .data The Lisp data to be used at load time


Note that the filetype of the fasl file is .fasl in KCL/AOS. Also note that the compiler of KCL/AOS generates an additional file ob-file. Accordingly, the function compile-file has a slightly different definition:



compile-file input-pathname[Function]

&key :output-file :fasl-file :c-file :h-file :ob-file :data-file

The keyword parameter :fasl-file corresponds to the keyword parameter :o-file in KCL on Unix. In particular, the default value of :fasl-file is t and the default values of :c-file, :h-file, :ob-file, and :data-file are all nil. In KCL/AOS,

          ) lc1  filename

has the same effects as (compile-file ``filename'' :fasl-file t :c-file t :h-file t :ob-file t :data-file t).


Because KCL/AOS follows the convention of the AOS/VS file system, the last example above should be replaced as:


( compile-file ``:udd:mas:foo'' :output-file ``:udd:tai:baa'')

The source file is ``FOO.LSP'' in the directory ``:UDD:MAS'', and the fasl file is ``BAA.FASL'' in the directory ``:UDD:TAI''.

———— End of Note ————



compile name &optional definition[Function]

If definition is not supplied, name should be the name of a not-yet-compiled function. In this case, compile compiles the function, replaces the previous definition of name with the compiled function,and returns name. If definition is supplied, it should be a lambda-expression to be compiled and name should be a symbol. If name is a non-nil symbol, then compile installs the compiled function as the function definition of name and returns name. If name is nil, then compile simply returns the compiled function.

The KCL compiler is essentially a file compiler, and forms to be compiled are supposed to be stored in a file. Thus compile actually creates a source file which contains the form designated by the arguments. Then compile calls compile-file to get a fasl file, which is then loaded into KCL. The source file and the fasl file are given the names gazonk.lsp and gazonk.fasl, respectively. These files are not deleted automatically after the execution of compile:.

disassemble &optional thing &key :h-file :data-file [Function]

This function does not actually disassemble. It always calls the KCL compiler and prints the contents of the c-file, i.e., the C-language code, generated by the KCL compiler. If thing is not supplied, or if it is nil, then the previously compiled form by disassemble will be compiled again. If thing is a symbol other than nil, then it must be the name of a not-yet-compiled function, whose definition is to be compiled. In this case, it is an error if the name is associated with a special form or a macro. If thing is a lambda-expression (lambda lambda-list . body), then disassemble first creates a function definition (defun gazonk lambda-list . body) and this definition is compiled. (The function name gazonk has no special meanings. Indeed, the displayed code is essentially independent of the function name.) Otherwise, thing itself will be compiled as a top-level form. In any case, disassemble does not install the compiled function. disassemble returns no value.

No intermediate h-file is created if the keyword parameter :h-file is nil or if :h-file is not supplied. Otherwise, an intermediate h-file is created under the name specified by :h-file. Similarly, the intermediate data-file is specified by the keyword parameter :data-file.

eval-when-compile*[Variable]

The compiler processes each top-level form in not-compile-time mode if the value of this variable isnil, and in compile-time-too mode, otherwise. See Section 5.3.3 of Common Lisp Reference Manual for these two modes. The initial value of this variable is t .